<?php
/**
 *  回傳多個亂數值
 * @author cik
 *
 */
class Sfs_Math_Mrand
{
    /**
     *   Multiple Unique Random Number
     * @param unknown_type $min
     * @param unknown_type $max
     * @param unknown_type $count
     * @param unknown_type $strLen
     * @return unknown_type
     */
    static public function  mrand($min,$max,$count,$strLen=false){
        if($min>$max){
            $a=$min;
            $b=$max;
            $max=$a;
            $min=$b;
        }
        if( (($max - $min) +1 ) < $count || $count <= 0 )
        return false;

        $result = array();

        if($strLen > 0){

            if(strlen($max) < $strLen && strlen($min) < $strLen)
            return false;
            if(strlen($max - 1 ) < $strLen && strlen($min - 1) < $strLen && $count > 1)
            return false;

            do{
                $x = rand($min,$max);
                if(!in_array($x, $result) && strlen($x) == $strLen)
                $result[] = $x;
            }while(count($result) < $count);

        }else{

            do{
                $x = rand($min ,$max);
                if(!in_array($x, $result))
                $result[] = $x;

            }while(count($result) < $count);

        }

        return $result;
    }
}